package signBean;

import java.sql.*;
import java.util.*;

public class DbManager {

	public Connection getConnection(){
		Connection con=null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sign?useUnicode=true&characterEncoding=utf-8","root","");
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return con;
	}
	
	public boolean checkUser(String uname,String password){
		Connection con=getConnection();
		boolean you=false;
		try {
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery("select * from a_user where uname='"+uname+"' and password='"+password+"'");
			if(rs.next()){
				you = true;
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			try{
				con.close();
			}catch(SQLException e){
				e.printStackTrace();
			}
		}
		return you;
	}
	public List getDate(String uname,String password){
		Connection con=getConnection();
		List list = new LinkedList();
	
		try {
			Statement st = con.createStatement();
			ResultSet rs = st.executeQuery("select * from a_user where uname='"+uname+"' and password='"+password+"'");
			while(rs.next()){
				String name = rs.getString("name");
				int id = rs.getInt("id");
				int auth = rs.getInt("auth");
				LoginDate lg = new LoginDate(name,id,auth);
				list.add(lg);
			}	
			

		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			try{
				con.close();
			}catch(SQLException e){
				e.printStackTrace();
			}
		}
		return list;
	}
		
}
	

